<style>
    .pageFormContent p{
        float:none;
    }



    .yuns label{
        width:auto;
        padding:0px 10px;
    }

    .pageFormContent .textInput{
        width:40px;
        float:none;
    }

    .pageFormContent p{
        width:auto;
    }

    ._citys {    display:none; background: #fff;width: 450px; z-index:1000;display: inline-block; border: 2px solid #eee; padding: 5px; position: relative; }
    ._citys span { color: #56b4f8; height: 15px; width: 15px; line-height: 15px; text-align: center; border-radius: 3px; position: absolute; right: 10px; top: 10px; border: 1px solid #56b4f8; cursor: pointer; }
    ._citys0 { width: 100%; height: 34px; display: inline-block; border-bottom: 2px solid #56b4f8; padding: 0; margin: 0; }
    ._citys0 li { display: inline-block; line-height: 34px; font-size: 15px; color: #888; width: 80px; text-align: center; cursor: pointer; }
    .citySel { background-color: #56b4f8; color: #fff !important; }
    ._citys1 { width: 100%; display: inline-block; padding: 10px 0; }
    ._citys1 a { width: 83px; height: 35px; display: inline-block; background-color: #f5f5f5; color: #666; margin-left: 6px; margin-top: 3px; line-height: 35px; text-align: center; cursor: pointer; font-size: 13px; overflow: hidden; }
    ._citys1 a:hover { color: #fff; background-color: #56b4f8; }
    .AreaS { background-color: #56b4f8 !important; color: #fff !important; }

    .anniu {
        background-color: #4CAF50; /* Green */
        margin-left: 10px;
        border-radius: 4px;
        color: white;
        padding: 3px 15px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        /*box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);*/
        cursor:pointer;
    }
    
    a{
        text-decoration:none;
    }

    .anniu:hover {
        box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
    }

    .dad {
        margin: 8px;
    }


</style>
<!-- <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<link href="css/default.css" rel="stylesheet" type="text/css" /> -->
<div class="pageContent">

    <form method="post" action="index.php?c=Goods&a=update" class="pageForm required-validate" onsubmit="return validateCallback(this,dialogAjaxDone); " enctype="multipart/form-data">
    <input type="hidden" name="s" id="" value="" class="imgName" style="width: 300px;"/>
    <input type="hidden" name="s1" id="" value="" class="imgName" style="width: 300px;" />
    <input type="hidden" name="goodsid" id="goodsid" value="{$goods.goodsid}">

        <div class="pageFormContent" layoutH="56">
            <div style="padding-bottom:20px;border-bottom:1px solid #eaeaea">添加商品:</div>
            <p>
                <label>商品名称：</label>
                <input name="title" type="text" size="50" class="required" style="width:150px;" value="{$goods.title}"/>
            </p>

            <p>
                <label>是否上架：</label>
                <if condition="$goods['shangjia'] eq 0">
                    <input type="radio" name="shangjia" value="0" checked="checked" class="isP"/>否
                    <input type="radio" name="shangjia" value="1" class="isP"/>是
                <else />
                    <input type="radio" name="shangjia" value="0"  class="isP"/>否
                    <input type="radio" name="shangjia" value="1" checked="checked" class="isP"/>是                
                </if>

<!--                 <input type="radio" name="shangjia" value="0" checked="checked" class="isP"/>否
                <input type="radio" name="shangjia" value="1" class="isP"/>是 -->
            </p>
            
            <p>
                <label>价格：</label>
                <input name="price" type="text" size="30" class="required" style="width:100px;" value="{$goods.price}" />
            </p>

            <p>
                <label>原价：</label>
                <input name="yuanjia" type="text" size="30" class="required" style="width:100px;" value="{$goods.yuanjia}"/>
            </p>

            <p>
                <label>起批量：</label>
                <input name="start_num_desc" type="text" size="30" class="required" style="width:150px;" placeholder="输入数量" value="{$goods.start_num}" />
                <input name="start_num" type="text" size="30" class="required" style="width:150px;"  placeholder="输入单位" value="{$goods.start_num_desc}"/>
            </p>
            
            <p>
                <label>简介：</label>
                <textarea name="summary" cols="20" class="required" rows="5" style="width: 400px; height: 200px;">{$goods.summary}</textarea>
            </p>

            <p style="margin-top: 200px;">
                <label>商品主图：</label>
                <div style="width: 610px; height: auto; border: 1px solid #e1e1e1; font-size: 12px; padding: 10px;">
                    <span id="spanButtonPlaceholder1"></span>
                    <div id="divFileProgressContainer1"></div>
                    <div id="thumbnails">
                        <ul id="pic_list1" style="margin: 5px;"></ul>
                        <div style="clear: both;"></div>
                    </div>
                </div>
            </p>

            <p style="margin-top: 50px;">
                <label>商品详情图：</label>
                <div style="width: 610px; height: auto; border: 1px solid #e1e1e1; font-size: 12px; padding: 10px;">
                    <span id="spanButtonPlaceholder2"></span>
                    <div id="divFileProgressContainer2"></div>
                    <div id="thumbnails">
                        <ul id="pic_list2" style="margin: 5px;"></ul>
                        <div style="clear: both;"></div>
                    </div>
                </div>
            </p>

            <p style="margin-top: 50px;">
                <label>商家：</label>
                    <select name="shopid" onchange="zileimu(this.value)">
                        <option value="{$moren_shopid.shopid}" selected="true">{$moren_shopid.name}</option>
                    <foreach name="shop" item="shop">
                        <option  value="{$shop.shopid}">{$shop.name}</option>
                    </foreach>
                    </select>
            </p>

            <p>
                <label>运费模板：</label>
                        <select name="muid">
                            <option value ="{$faremlid.id}">{$faremlid.name}</option>
                        <foreach name="fareml" item="fareml">
                            <option value ="{$fareml.id}">{$fareml.name}</option>
                        </foreach>
                        </select>
            </p>

            <p>
                <label>子分类：</label>
                        <select name="zixilie" id="zixilie">
                            <option value ="{$goods.zixilie}">{$goods.name}</option>
                        <foreach name="zileimu" item="zileimu">
                            <option value ="{$zileimu.id}">{$zileimu.name}</option>
                        </foreach>
                        </select>
            </p>

            <p>
                <label>支持返券：</label>
                <if condition="$goods['can_fanquan'] eq 0">
                <input type="radio" name="can_fanquan" value="0" checked="checked" class="isP"/>否
                <input type="radio" name="can_fanquan" value="1" class="isP"/>是
                <else />
                <input type="radio" name="can_fanquan" value="0" class="isP"/>否
                <input type="radio" name="can_fanquan" value="1" checked="checked" class="isP"/>是
                </if>
            </p>

            <p>
                <label>猜你喜欢：</label>
                <if condition="$goods['xihuan'] eq 0">
                <input type="radio" name="xihuan" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="xihuan" value="1"  class="isP"/>开启
                <else />
                <input type="radio" name="xihuan" value="0" class="isP"/>关闭
                <input type="radio" name="xihuan" value="1" checked="checked" class="isP"/>开启
                </if>
            </p>

            <p>
                <label>特价：</label>
                <if condition="$goods['tejia'] eq 0">
                <input type="radio" name="tejia" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="tejia" value="1" class="isP"/>开启
                <else />
                <input type="radio" name="tejia" value="0" class="isP"/>关闭
                <input type="radio" name="tejia" value="1" checked="checked" class="isP"/>开启
                </if>
            </p>

            <p>
                <label>扫货：</label>
                <if condition="$goods['act_saohuo'] eq 0">
                <input type="radio" name="act_saohuo" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_saohuo" value="2" class="isP"/>开启
                <else />
                <input type="radio" name="act_saohuo" value="0" class="isP"/>关闭
                <input type="radio" name="act_saohuo" value="2" checked="checked" class="isP"/>开启
                </if>
            </p>

            <p>
                <label>限时折扣：</label>
                <if condition="$goods['act_xianshizhekou'] eq 0">
                <input type="radio" name="act_xianshizhekou" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_xianshizhekou" value="2"  class="isP"/>开启
                <else />
                <input type="radio" name="act_xianshizhekou" value="0" class="isP"/>关闭
                <input type="radio" name="act_xianshizhekou" value="2" checked="checked" class="isP"/>开启
                </if>
            </p>

            <p>
                <label>首选精品：</label>
                <if condition="$goods['act_shouxuanjingpin'] eq 0">
                <input type="radio" name="act_shouxuanjingpin" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_shouxuanjingpin" value="2" class="isP"/>开启
                <else />
                <input type="radio" name="act_shouxuanjingpin" value="0" class="isP"/>关闭
                <input type="radio" name="act_shouxuanjingpin" value="2" checked="checked" class="isP"/>开启
                </if>
            </p>

            <p>
                <label>你想要的：</label>
                <if condition="$goods['act_shouxuanjingpin'] eq 0">
                <input type="radio" name="act_nixiangyaode"  value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_nixiangyaode" value="2" class="isP"/>开启
                <else />
                <input type="radio" name="act_nixiangyaode"  value="0" class="isP"/>关闭
                <input type="radio" name="act_nixiangyaode" value="2" checked="checked"  class="isP"/>开启
                </if>
            </p>
            
            <div>
            <p>
                <label>规格：</label>
                <div class="parents">
                    
                </div>
                <a onclick="add_main_class()" class="anniu">添加</a>
            </p>
            </div>

        </div>
        <div class="formBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit">保存</button>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="button">
                        <div class="buttonContent">
                            <button type="button" class="close">取消</button>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<script>
   var i = -1;
   var j = -1;
    function add_main_class() {
        i++;
        var num = Math.floor(Math.random()*100);
        var html = "";
            html += "<div class='dad" + num + " dad'>";
            html += "名字<input name='guige["+ num +"][fTitle]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位' value='' id='ftitle" + num + "' />";
            html += "价格<input name='guige["+ num +"][price]' type='text' size='30'  style='width:150px;'  placeholder='输入单位' value='' id='ftitle" + num + "' />";
            html += "数量<input name='guige["+ num +"][number]' type='text' size='30'  style='width:150px;'  placeholder='输入单位'/>";
            html += "<a onclick='removeDiv("+ num +")' class='anniu'>删除</a>";
            html += "<a onclick='add_son("+ num +")' class='anniu'>添加子类</a>";
            html += "</div>";
        $('.parents').append(html);
    }

    function add_son(num) {
        var name = '.dad' + num;
        j++;

        var html = "";
        if($(name).find("div").length>0){
            html += "<div class='son"+ num +"' style='margin-left:50px; margin-top:10px;'>";
            html += "<input name='guige["+ j +"][fTitle]' type='hidden' size='30'  style='width:150px;' value='" + val + "'/>";
            html += "子类<input name='guige["+ j +"][sTitle]' type='text' size='30'  style='width:150px;'  placeholder='输入单位'/>"; 
            html += "价格<input name='guige["+ j +"][price]' type='text' size='30'  style='width:150px;'/>";
            html += "数量<input name='guige["+ j +"][number]' type='text' size='30'  style='width:150px;'  placeholder='输入单位'/>";
            html += "<a onclick='removeDiv("+ num +")' class='anniu'>删除</a>";
            html += "</div>";
            $(name).append(html);
        } else {
            // html += "<div class='dad" + num + "'>";
            html += "名字<input name='guige["+ j +"][fTitle]' type='text' size='30'  style='width:150px;' value='' id='ftitle" + num + "' />";
            html += "<a onclick='add_son("+ num +")' class='anniu'>添加子类</a>";
            html += "<div class='son"+ num +"' style='margin-left:50px; margin-top:10px;'>";
            html += "子类<input name='guige["+ j +"][sTitle]' type='text' size='30'  style='width:150px;' />";    
            html += "价格<input name='guige["+ j +"][price]' type='text' size='30'  style='width:150px;'/>";
            html += "数量<input name='guige["+ j +"][number]' type='text' size='30'  style='width:150px;'  placeholder='输入单位'/>";
            // html += "ID<input  type='text' size='30' class='required' style='width:150px;'  value='111'/>";
            html += "<a onclick='removeDiv("+ num +")' class='anniu'>删除</a>";
            html += "</div>";
            // html += "</div>";
            $(name).html(html);
        }
    }

    function removeDiv(num, selectid){
        if(selectid) {
            $.ajax({
              type:"POST",
              async: false,
              url: "index.php?c=Goods&a=del_guige",
              data: {"selectid":selectid},
              dataType:'json',
              success:function(data){

                }
            });
        }
        var dadname = '.dad' + num;
        var soname = '.son' + num;
        $(dadname).remove();
        $(soname).remove();

    }

    $(document).ready(function(){ 
        var goodsid = $("#goodsid")[0].value; 

        $.ajax({
          type:"POST",
          url: "index.php?c=Goods&a=get_guige",
          data: {"goodsid":goodsid, "type":1},
          dataType:'json',
          success:function(data){
            var html = "";
            if(data['guige_dad'] == null && data['guige_son'] == null) {
                return false;
            }

            for(i=0;i<data['guige_dad'].length;i++) {
                var num = Math.floor(Math.random()*100);
                html += "<div class='dad" + num + " dad'>";
                html += "名字<input name='guige[fTitle]' type='text' size='30'  style='width:150px;' value='" + data['guige_dad'][i]['fTitle'] +"' id='ftitle" + num + "' />";
                html += "<a onclick='add_son("+ num +")' class='anniu' >添加子类</a>";

                for(j=0;j<data['guige_son'].length;j++) {
                     var num = Math.floor(Math.random()*100);
                    if(data['guige_dad'][i]['fTitle'] == data['guige_son'][j]['fTitle']) {
                        html += "<div class='son"+ num +"' style='margin-left:50px; margin-top:10px;'>";
                        html += "<input name='guige["+ j +"][fTitle]' type='hidden' size='30'  style='width:150px;' value='" + data['guige_dad'][i]['fTitle'] +"' id='ftitle" + num + "' />";
                        html += "<input name='guige["+ j +"][selectid]' type='hidden' size='30'  style='width:150px;' value='" + data['guige_son'][j]['selectid'] +"' id='ftitle" + num + "' />";
                        html += "子类<input name='guige["+ j +"][sTitle]' type='text' size='30'  style='width:150px;' value='" + data['guige_son'][j]['sTitle'] + "'/>";    
                        html += "价格<input name='guige["+ j +"][price]' type='text' size='30'  style='width:150px;' value='" + data['guige_son'][j]['price'] + "'/>";
                        html += "数量<input name='guige["+ j +"][number]' type='text' size='30'  style='width:150px;' value='" + data['guige_son'][j]['number'] + "'/>"; 
                        html += "<a onclick='removeDiv("+ num +","+ data['guige_son'][j]['selectid'] + ")' class='anniu'>删除</a>";
                        html += "</div>";
                    }
                }
                html += "</div>";
                $('.parents').html(html);
            }
          }
        });
    });

    function zileimu(shopid) {
        $.ajax({
          type:"POST",
          async: false,
          url: "index.php?c=Goods&a=zifenlei",
          data: {"shopid":shopid},
          dataType:'json',
          success:function(data){
                var html = '';
                for(i=0;i<data.length;i++) {
                    html += "<option value =" + data[i]['id'] + ">"+ data[i]['name'] +"</option>";
                }
                $('#zixilie').html(html);
            }
        });
    }
</script>
<script type="text/javascript">
        var swfu1;
        var swfu2;
        $(document).ready(function(){ 
                swfu1 = new SWFUpload({
                    upload_url: "index.php?c=Goods&a=uploadImg",
                    post_params: {"type" : "0"},
                    file_size_limit : "2 MB",
                    file_types : "*.jpg;*.png;*.gif;*.bmp",
                    file_types_description : "JPG Images",
                    file_upload_limit : "100",
                    file_queue_error_handler : fileQueueError,
                    file_dialog_complete_handler : fileDialogComplete,
                    upload_progress_handler : uploadProgress,
                    upload_error_handler : uploadError,
                    upload_success_handler : uploadSuccess,
                    upload_complete_handler : uploadComplete,
                    button_image_url : "Public/images/upload.png",
                    button_placeholder_id : "spanButtonPlaceholder1",
                    button_width: 113,
                    button_height: 33,
                    button_text : '',
                    button_text_style : '.spanButtonPlaceholder { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;} ',
                    button_text_top_padding: 0,
                    button_text_left_padding: 0,
                    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                    button_cursor: SWFUpload.CURSOR.HAND,           
                    flash_url : "swf/swfupload.swf",
                    custom_settings : {
                        upload_target : "divFileProgressContainer1",
                        // cancelButtonId : "btnCancel1"

                },              
                debug: false
            });
                swfu2 = new SWFUpload({
                    upload_url: "index.php?c=Goods&a=uploadImg",
                    post_params: {"type" : "1"},
                    file_size_limit : "2 MB",
                    file_types : "*.jpg;*.png;*.gif;*.bmp",
                    file_types_description : "JPG Images",
                    file_upload_limit : "100",
                    file_queue_error_handler : fileQueueError,
                    file_dialog_complete_handler : fileDialogComplete,
                    upload_progress_handler : uploadProgress,
                    upload_error_handler : uploadError,
                    upload_success_handler : uploadSuccess,
                    upload_complete_handler : uploadComplete,
                    button_image_url : "Public/images/upload.png",
                    button_placeholder_id : "spanButtonPlaceholder2",
                    button_width: 113,
                    button_height: 33,
                    button_text : '',
                    button_text_style : '.spanButtonPlaceholder { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;} ',
                    button_text_top_padding: 0,
                    button_text_left_padding: 0,
                    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                    button_cursor: SWFUpload.CURSOR.HAND,           
                    flash_url : "swf/swfupload.swf",
                    custom_settings : {
                        upload_target : "divFileProgressContainer2",
                        // cancelButtonId : "btnCancel2"

                },              
                debug: false
            });
        }); 
</script>
<script type="text/javascript">
$(function(){
    var goodsid = $('#goodsid').val();
    $(document).ready(function() {
            $.ajax({
              type:"POST",
              url: "index.php?c=Goods&a=get_img",
              data: {"goodsid":goodsid,},
              dataType:'json',
              success:function(array){
                    var html = "";
                    var html1 = ""; 
                    var img = "";
                    var img1 = "";
                    if(array['images'] != undefined) {
                        for(var i=0;i<array['images'].length;i++) {
                            var shu = i+1;
                            html += "<li style='margin-left:0px;'>";
                            html += "<img class='content' src='../" + array['images'][i] + "' style='width: 100px; height: 100px;'>";
                            html += "<img class='button1' src='Public/images/fancy_close.png'>";
                            html += "<input id='imgId' class='imgId" + shu + "' type='hidden' value='" + shu +"'>";
                            html += "</li>";
                            img += array['images'][i] + ',';
                        }
                    }

                    console.log(array['xiangQingTu']);
                    if(array['xiangQingTu'] != undefined) {
                        for(var i=0;i<array['xiangQingTu'].length;i++) {
                            var shu = i+1;
                            html1 += "<li style='margin-left:0px;'>";
                            html1 += "<img class='content' src='../" + array['xiangQingTu'][i] + "' style='width: 100px; height: 100px;'>";
                            html1 += "<img class='button2' src='Public/images/fancy_close.png'>";
                            html1 += "<input id='imgId' class='imgId" + shu + "' type='hidden' value='" + shu +"'>";
                            html1 += "</li>";
                            img1 += array['xiangQingTu'][i] + ',';
                        }       
                    }

                    var images = img.slice(0,-1);
                    var images1 = img1.slice(0,-1);

                    $("#pic_list1").append(html);
                    $("#pic_list2").append(html1);

                    $("img.button1").bind("click", del1);
                    $("img.button2").bind("click", del2);
                    $('form>input[name=s]').val(images);
                    $('form>input[name=s1]').val(images1);
                  }
              
            });
    });
});
</script>